
<?php
session_start(); //开启会话
?>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>会员资料修改</title>
    <style>
        html {
            width: 100%;
            height: 100%;
        }

        body {
            margin: 0 auto;
            padding: 0 auto;
            position: relative;
            background-repeat: no-repeat;

            background-position: center center;

            /*background-color: #00BDDC;*/


            background-size: 100% 100%;
        }
        h1 {
            /*text-align: left;*/
            color: white;
        }
        b{
            font-size: 20px;
            margin-left: 30px;
            color: rgba(255, 138, 36, 0.7)
        }


        table {
            border-collapse: collapse;
            background-color: rgba(250, 152, 98, 0.9);
            text-align: center;
            width: 400px;
            border-radius: 20px;

        }
        table tr{
            width: 400px;
        }
        td {

            border-bottom: 1px solid #fff;
            padding: 8px;
        }

        .sure {
            color: red;
        }
        /*input[type="radio"]{*/
        /*border: 1px solid #2cc1ec;*/
        /*border-radius: 5px;*/
        /*}*/
        input[type="text"],input[type="password"]{
            outline: none;
            border:1px solid #2cc1ec;
            border-radius: 5px;
            width: 165px;
            height: 23px;
        }
        input[type="submit"],input[type="reset"]，input[type="buttom"]{
            outline: none;
            width: 60px;
            /*background-color: #2cc1ec;*/
        }

        #all{
            position: absolute;
            top: 180px;
            width: 100%;
            background-color:rgba(255, 255, 255, 0.4); ;
        }

    </style>
</head>
<body>
<h1>会员资料修改</h1>
<?php
//先判断是否登录，本页面只有登录后才能访问

if (!isset($_SESSION['loggedUsername']) or !$_SESSION['loggedUsername']) {  //说明未登录
    echo "<script>alert('本页面需要登录后才能访问，请登录！');location.href='login.html';</script>";
    exit;
}
//将当前用户的资料从数据库中读出来，并显示在页面中。
include_once "conn.php";
$sql = "select * from userinfo where username = '" . $_SESSION['loggedUsername'] . "'";
$result = mysqli_query($conn, $sql);
$num = mysqli_num_rows($result);
if (!$num) { //当前用户不存在
    echo "<script>alert('当前用户不存在！');location.href='login.html';</script>";
    exit;
} else { //说明找到了当前用户
    $info = mysqli_fetch_array($result, 1);
}
?>
<form action="modifySure1.php" method="post" enctype="multipart/form-data">
    <table align="center" style="border-collapse: collapse" border="1" bordercolor="#999999">
        <tr>
            <td align="right">用户名 </td>
            <td align="left"><input name="u1" placeholder="请输入用户名" id="username" type="text" value="<?php echo $info['username']; ?>" readonly><span
                        class="sure"> *</span></td>
        </tr>
        <tr>
            <td align="right">密码 </td>
            <td align="left"><input type="password" name="pw" id="pw" placeholder="如果不修改密码请留空">
                <span id="pwTips"></span>
            </td>
        </tr>
        <tr>
            <td align="right">确认密码</td>
            <td align="left"><input type="password" name="cpw" id="cpw" placeholder="如果不修改密码请留空"><span id="cpwTips"></span></td>
        </tr>
        <tr>
            <td>请输入验证码:</td>
            <td><input type="text" name="code" id="code">
                <img src="code.php" onclick="this.src='code.php? ' + new Date().getTime()"</td>
        </tr>
        <tr>
            <td align="right"><input type="submit" name="submit" value="修改" onclick=" return jQueryCheck();"></td>
            <td align="left"><input type="reset" name="reset" value="重置"><input type="button" value="返回" onclick="javascript:location.href='index.php'"></td>
        </tr>
    </table>
</form>
<script src="js/jquery-1.9.1.min.js"></script>
<script>
    $(function () {

    });

    function jQueryCheck() {
        var  pw, cpw,errLog = 0, errMsg = "", code;
        pw = $("#pw").val().trim();
        cpw = $("#cpw").val().trim();
        code = $("#code").val().trim();
        if (pw != cpw) {
            errLog = 1;
            errMsg += "密码和确认密码必须相同！\n";
        }
        if (code == "") {
            errLog = 1;
            errMsg += "请输入验证码!";
        }
        if (errLog == 1) {
            alert(errMsg);
            return false;
        }
    }

    function check() {
        var username, pw;
        username = document.getElementById("username").value.trim();
        if (username == "") { //说明用户名未填写
            alert("用户名必须填写！");
            return false;
        }
        pw = document.getElementById("pw").value.trim();
        if (pw == "") { //说明用户名未填写
            alert("密码必须填写！");
            return false;
        }
    }
</script>
</body>
</html>